#!/usr/local/bin/bash

if [ "$1" = "-h" ]; then
	echo "Usage: $0 filecount repeated name file"
	echo "filecount - # of files, only with rand"
	echo "repeated - # of repetition"
	echo "name - filename"
	echo "dirname - dir of copyed files"
	exit 1
fi

if [ $# -lt 3 ]; then
	echo "Usage: $0 filecount repeated name [size rand | dirsrc dirdest]"
	exit 1
fi

	
START=1
FCOUNT=$1
REPEATED=$2
NAME=$3
RAND=""

RNDCOUNT=20
DIRSRC=""
DIRDEST=""

if [ "$5" = "rand" ]; then
	SIZE=$4
	RAND=$5
elif [ "$4" = "big" ]; then
	DIRSRC="_big"
	DIRDEST=$5
elif [ "$4" = "small" ]; then
	DIRSRC="_small"
	DIRDEST=$5
elif [ "$4" = "normal" ]; then
	DIRDEST="$5"
elif [ "$4" != "" ]; then
	DIRSRC="_$4"
fi

if [ "$DIRDEST" != "" ]; then 
	mkdir /home/filedisk/$DIRDEST
fi


RNDFILES="/home/tomas/Diplomka/udefrag/scripts/genfiles$DIRSRC/gen_"
#RNDFILES=`dirname $0`/genfiles_big/gen_
#RNDFILES=`dirname $0`/genfiles_small/gen_

while [ $START -le $REPEATED ]
do
	FI=1
	while [ $FI -le $FCOUNT ]
	do
		if [ "$RAND" = "" ]; then
			cat $RNDFILES$((RANDOM%RNDCOUNT)) >> /home/filedisk/$DIRDEST/$NAME$FI
		else
			dd if=/dev/urandom of=/tmp/frag bs=$SIZE count=1
			cat /tmp/frag >> /home/filedisk/$NAME$FI
		fi
		FI=`expr $FI + 1`
	done
	START=`expr $START + 1`
done

